<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* 	Class Name	: Reporter
	Author 		: Iswan Putera S.Kom
	Version		: 1.0
	Date		: 27 May 2013
*/

class Akunreport extends CI_Controller
{
	function __construct()
	{
		parent::__construct();	
		$this->load->model('main_model');
		$this->load->library('zetro_auth');
		//$this->load->library('zetro_func');
		//force_ssl();
	}
	function jurnal()
	{
			$data=array();
			$this->zetro_form->AddFilter($this->zetro_form->FilterTgl(true,true));
			$data['tab_header']=$this->zetro_form->generate_tab_header('Jurnal.');
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('report_jurnal');
			$content='';
			$this->zetro_form->section('rptjurnal');
			$this->zetro_form->action_col(false);
			$this->zetro_form->tabel_content($content);
			$data['list']=$this->zetro_form->list_std('NewList','100%');
			
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltrptjurnal');
			$data['frm']=$this->zetro_form->frm_std('frm1');
			$data['modal']=$this->zetro_form->PrintPreview('Jurnal');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_jurnal',$data);
			$this->load->view('admin/footer');
	}
	
	function get_jurnal()
	{
		$content="";
		$ordby=empty($_POST['ordby'])?'idtrans':$_POST['ordby'];
		//$this->main_model->where(array('bln'=>$_POST['bulan'],'thn'=>$_POST['tahun']));
		$this->main_model->where(array('tgljurnal <='=>tgltoSql($_POST['upto_tgl']),'tgljurnal >='=>tgltoSql($_POST['from_tgl'])));
		$datax=$this->main_model->generate_list('v_jurnal',$ordby);
			foreach($datax as $d)
			{
				$content.=tr('tree '.str_replace('.','_',$d->notrans).'\' id=\''.$d->idtrans.'\' style=\'display:').
						  td($d->tgljurnal,false,'','','center').
						  td($d->koderek,false,'','','left').
						  td($d->keterangan,false,'','','left').
						  td($d->nobukti,false,'','','left').
						  td($d->reff,false,'','','center').
						  td(number_format($d->debet,2),false,'','','right').
						  td(number_format($d->kredit,2),false,'','','right').
						  _tr();
				}
			$content.=$this->zetro_form->DataNotFound($datax,8);
			echo $content;
	}
	function get_tahun_jurnal($feedback=false)
	{
		$data=array();
		$data=$this->main_model->generate_list('v_jurnal_tahun','tahun');
		$content="<option value=''>&nbsp</option>";
		foreach($data as $r)
		{
			$slct=($r->tahun==date('Y'))?" selected='selected'":"";
			$content.= "<option value='".$r->tahun."'".$slct.">".($r->tahun)."</option>";	
		}
		if($feedback==true){ return $content;}else{ echo $content;}
	}
	
	function print_jurnal()
	{
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$ordby=empty($_POST['ordby'])?'idtrans':$_POST['ordby'];
		$this->main_model->where(array('tgljurnal <='=>tgltoSql($_POST['upto_tgl']),'tgljurnal >='=>tgltoSql($_POST['from_tgl'])));
		$data['lst']=$this->main_model->generate_list('v_jurnal',$ordby);
		//print_r($data);
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_jurnal_print', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_jurnal');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_jurnal.pdf';
	}
	
	//buku besar
	
	function bukubesar()
	{
			$data=array();
			//$this->zetro_form->AddFilter($this->zetro_form->FilterTgl(true,true,true));
			$data['tab_header']=$this->zetro_form->generate_tab_header('Buku Besar',false);
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('buku_besar');
			$content='';
			$this->zetro_form->generate_dropdown_content('akun_unitbussiness','id_unit','nm_unit');
			$this->zetro_form->section('rptbukbes');
			$this->zetro_form->action_col(false);
			$this->zetro_form->tabel_content($content);
			$data['list']=$this->zetro_form->list_std('NewList','100%');
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltrptbukbes');
			$data['frm']=$this->zetro_form->frm_std('frm1');
			$data['modal']=$this->zetro_form->PrintPreview();
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_bukubesar',$data);
			$this->load->view('admin/footer');
	}
   
   function print_bukubesar()
	{
		//collect data
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$data['id_akun']=$_POST['id_akun'];
		$data['nm_akun']=$this->main_model->rdb('v_akun_display','cnama',"where ckode='".$_POST['id_akun']."'");
		$ordby=empty($_POST['ordby'])?'id_trans':$_POST['ordby'];
		$this->main_model->where_or(array("substring_index(id_akun,':',1)"=>$_POST['id_akun']));
		$this->main_model->where_or(array("substring_index(id_akun_kontra,':',1)"=>$_POST['id_akun']));
		$this->main_model->where(array('tgl_trans <='=>tgltoSql($_POST['upto_tgl']),'tgl_trans >='=>tgltoSql($_POST['from_tgl'])));
		empty($_POST['id_unit'])?'':
		$this->main_model->where(array('id_unit'=>$_POST['id_unit']));
		$this->main_model->group_by('id_trans');
		$data['lst']=$this->main_model->generate_list('v_jurnal',$ordby);
		$data['ub']=empty($_POST['id_unit'])?'':$_POST['id_unit'];
		//generate PDF
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_bukubesar_print', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_bukubesar');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_bukubesar.pdf';
	}
	//neraca lajur
	function neracal()
	{
			//generate tabheader
			$data['tab_header']=$this->zetro_form->generate_tab_header('Neraca Lajur',false);
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('neraca_percobaan');
			//genarate form
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltrptneracal');
			$data['frm']=$this->zetro_form->frm_std('frm1');
			$data['modal']=$this->zetro_form->PrintPreview('Neraca Percobaan');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_neracal',$data);
			$this->load->view('admin/footer');
	}
	
	function print_neracacal()
	{
		//collect data
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$ordby=empty($_POST['ordby'])?'kd_neraca':$_POST['ordby'];
		//$this->main_model->where(array('koderek'=>$_POST['id_akun'],'tgljurnal <='=>tgltoSql($_POST['upto_tgl']),'tgljurnal >='=>tgltoSql($_POST['from_tgl'])));
		$this->main_model->where(array('length(kd_akun)'=>'3'));
		$data['from_tgl']=$_POST['from_tgl'];
		$data['up_tgl']  =$_POST['upto_tgl'];
		$data['lst']	 =$this->main_model->generate_list('v_akun_neraca',$ordby);
		$data['lvl']	 =$_POST['lvl_akun'];
		//generate PDF
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_neracalajur', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_neracalajur', true,'landscape','legal');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_neracalajur.pdf';/**/
	}
	//report neraca
	function neraca()
	{
			//generate tabheader
			$data['tab_header']=$this->zetro_form->generate_tab_header('Neraca',false);
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('neraca');
			//genarate form
			$this->zetro_form->generate_dropdown_content('akun_unitbussiness','id_unit','nm_unit');
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltrptneraca');
			$data['frm']=$this->zetro_form->frm_std('frm1');
			$data['modal']=$this->zetro_form->PrintPreview('Neraca');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_neraca',$data);
			$this->load->view('admin/footer');
	}
	function print_neraca()
	{
		//collect data
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$data['from_tgl']=$_POST['from_tgl'];
		//$data['up_tgl']  =$_POST['upto_tgl'];

		$ordby=empty($_POST['ordby'])?'kd_akun':$_POST['ordby'];
		$this->main_model->where(array('length(kd_akun)'=>'3'));
		$data['lst']=$this->main_model->generate_list('v_akun_neraca',$ordby);
		$data['lvl']=$_POST['lvl_akun'];
		$data['ub']=empty($_POST['id_unit'])?'':$_POST['id_unit'];
		//generate PDF
		/*print_r($data);*/
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_neraca_z', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_neraca');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_neraca.pdf';/**/
	}
   //rugi laba
	function labarugi()
	{
			//generate tabheader
			$data['tab_header']=$this->zetro_form->generate_tab_header('Rugi Laba',false);
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('rugi_laba');
			//genarate form
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltrptneracal');
			$data['frm']=$this->zetro_form->frm_std('frm1');
			$data['modal']=$this->zetro_form->PrintPreview('Rugi Laba');
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_rugilaba',$data);
			$this->load->view('admin/footer');
	}
	function print_rugilaba()
	{
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$data['from_tgl']=$_POST['from_tgl'];
		$data['up_tgl']  =$_POST['upto_tgl'];
		$data['lvl']	=$_POST['lvl_akun'];
		$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
		$this->main_model->where(array('left(ckode,1) >'=>'3','levele'=>'2'));
		$data['lst']=$this->main_model->generate_list('v_akun_display',$ordby);
		//generate PDF
		/*print_r($data);*/
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_rugilaba_print', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_rugilaba');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_rugilaba.pdf';/**/
	}
	
	function balance()
	{
			//generate tabheader
			$data['tab_header']=$this->zetro_form->generate_tab_header('Balance Sheet',false);
			$this->zetro_form->frm_file('asset/frm/zetro_akun.frm');
			$this->zetro_auth->menus('balance_sheet');
			//genarate form
			$this->zetro_form->addButtons(true);
			$this->zetro_form->buttons(false);
			$this->zetro_form->section('fltbalance');
			$data['frm']	=$this->zetro_form->frm_std('frm1');
			$data['modal']  =$this->zetro_form->PrintPreview('Balance Sheet');
			$data['thn']	=$this->get_tahun_jurnal(true);
			//send data to view
			$this->load->view('admin/header');
			$this->load->view('accounting/rpt_balance',$data);
			$this->load->view('admin/footer');
	}
	
	function balance_print()
	{
		$data=array();
		$data['coy']	=$this->zetro_form->infoCo('Nama');
		$data['add']	=$this->zetro_form->infoCo('Address');
		$data['kota']   =$this->zetro_form->infoCo('City');
		$data['keua']   =$this->zetro_form->infoCo('AccHead');
		$data['bln']	=$_POST['bln'];
		$data['thn']  	=$_POST['thn'];
		$data['lvl']	=$_POST['lvl_akun'];
		$data['where_lalu']=($_POST['bln']=='1')?" and month(tgljurnal)='12' and year(tgljurnal)='".($_POST['thn']-1)."'":
							" and month(tgljurnal)<'".$_POST['bln']."' and year(tgljurnal)='".$_POST['thn']."'";
		$data['where_ini']=" and month(tgljurnal)='".$_POST['bln']."' and year(tgljurnal)='".($_POST['thn'])."'";
		$data['where_ytd']=" and month(tgljurnal)<='".$_POST['bln']."' and year(tgljurnal)='".$_POST['thn']."'";
		$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
		$this->main_model->where(array('igrup'=>'0','levele '=>'2'));
		$data['lst']=$this->main_model->generate_list('v_neraca',$ordby);
		$this->main_model->where(array('igrup'=>'1','levele ='=>'1'));
		$data['lst2']=$this->main_model->generate_list('v_neraca',$ordby);
		$data['lvl']=$_POST['lvl_akun'];
		//generate PDF
		$this->load->library('zetro_dompdf');
		$html = $this->load->view('accounting/rpt_balance_print', $data, true);
		$this->zetro_dompdf->createPDF($html, $this->session->userdata('userid').'_balance');
		echo base_url().'application/logs/'.$this->session->userdata('userid').'_balance.pdf';/**/
	}
//end of class akun report	
}
